<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class Article extends Model
{

    protected $table = 'article';

    protected $guarded = [];

    public $timestamps = false;


    // 文章属于某一个章节
    public function chapter(){

        return $this->belongsTo(Chapter::class,'chapter_num','chapter_num');

    }

    protected static function boot()
    {
        parent::boot();


        static::creating(function ($article){

            $article->create_time = time();
            $article->status = 3;


        });

        static::updating(function ($article){

            $article->last_editdate = time();
            $article->word_count = strlen(trim($article->article));

        });



    }


}
